package geektime.spring.springbucks.mapper;

import geektime.spring.springbucks.model.Coffee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;

import java.util.List;

@Mapper
public interface CoffeeMapper {
    @Select("select * from t_coffee order by id")
    List<Coffee> findAllWithRowBounds(RowBounds rowBounds);

    @Select("select * from t_coffee order by id")
    List<Coffee> findAllWithParam(@Param("pageNum") int pageNum,
                                  @Param("pageSize") int pageSize);

    @Insert("insert into t_coffee (name, price, create_time, update_time)"
            + "values (#{name}, #{price,jdbcType=BIGINT,typeHandler=geektime.spring.springbucks.handler.MoneyTypeHandler}, now(), now())")
    @Options(useGeneratedKeys = true)
    int save(Coffee coffee);

    @Update("UPDATE t_coffee SET price = #{price,jdbcType=BIGINT,typeHandler=geektime.spring.springbucks.handler.MoneyTypeHandler},update_time = NOW() WHERE id = #{id}")
    int updateCoffeePrice(Coffee coffee);

    @Delete("DELETE FROM t_coffee WHERE id = #{id}")
    int deleteByPrimaryKey(@Param("id") Long id);
}
